#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>

int main(){

printf("Debut du program principal\n");

int x=getpid();
printf("My process id is: %d \n\n", x);

int newid = fork();
if (newid == 0){
//partie executee en cas de success du fork
	fprintf(stdout,"==>CHILD PID=%d\n\n",getpid());
	exit(0);
}
else if (newid < 0){
	//partie executee en cas d eche du fork
	fprintf(stdout,"==>FAILED to create a child process \n\n");
	exit(1);
}
else
{
//partie executee UNIQUEMENT par le main
	printf("Fin du program principal\n\n");
	
}
if (newid)
{
	int w;
	pid_t pid_pot;
	/*
	A child that terminates, but has not been waited for becomes a "zombie".  The kernel maintains
        a minimal set of information about the zombie process (PID, termination status, resource usage
        information) in order to allow the parent to later perform a wait to obtain information  about
  	the  child.
	*/
	pid_pot= wait(&w);
	printf("Child process PID =%d work finished \n",pid_pot);
	printf("Return code of child process: %d\n", w);

}

return 0;
}
